package encrypt;
import db.CryptField;
import db.RandomGenerator;
/**
 * <b>注意事项</b>
 * <ul>
 * <li>加密字段现在只支持String byte[](byte数组) </li>
 * <li> String byte[]加密后长度会增加，<br/>
 *      String时,使用 16 + 6 * 原长 <br/>
 * </li>
 * <li>加密字段的操作 <br/>
 * <ul>
 * <li>支持 等于 不等 关系操作<br/>
 * where pwd='abc' or pwd != 'xyz' <br/></li>
 * <li>不支持 > < 赋值= order 操作<br/>
 * where birthday > date('now','localtime')<br/>
 * set age = age + 1 <br/>
 * order by age asc <br/></li>
 * </ul>
 * </li>
 * </ul>
 */

public class BeanAbc {
    private String name;
    private int age;

    @CryptField(colName = "password")
    private String password; //对此字段加密

    @CryptField(colName = "stuff")
    private byte[] stuff;//对此字段加密

    public BeanAbc() {
        super();
    }
    public BeanAbc(String name, int age, String password, byte[] stuff) {
        this.name = name;
        this.age = age;
        this.password = password;
        this.stuff = stuff;
    }

    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public int getAge() {
        return age;
    }
    public void setAge(int age) {
        this.age = age;
    }
    public String getPassword() {
        return password;
    }
    public void setPassword(String password) {
        this.password = password;
    }

    public byte[] getStuff() {
        return stuff;
    }
    public void setStuff(byte[] stuff) {
        this.stuff = stuff;
    }

    @Override
    public String toString() {
        return "BeanAbc{" +
                "name='" + name + '\'' +
                ", age=" + age +
                ", password='" + password + '\'' +
                ", stuff=" + CryptUtils.printByteArray(stuff) +
                '}';
    }


    public static BeanAbc generatRdmObject() {
        String name = RandomGenerator.randomString(6);
        int age = RandomGenerator.randomInt(0, 99);
        String pwd = RandomGenerator.randomString(8);
        byte[] bytes = RandomGenerator.randomBytes(3);

        return new BeanAbc(name, age, pwd, bytes);
    }
}